USE [CTEM-DB-v1]
GO

/****** Object:  StoredProcedure [dbo].[WorkersSalary_Delete]    Script Date: 02/10/2012 11:13:13 ******/
SET ANSI_NULLS ON
GO

SET QUOTED_IDENTIFIER ON
GO

-- =============================================
-- Author:		TienDH
-- Create date: 12/05/2011
-- Description:	Get full employee's information
-- =============================================
CREATE PROCEDURE [dbo].[WorkersSalary_Delete]
	@workersSalaryID        bigint
AS
	
BEGIN
	   --DELETE DAYWORKING
		DECLARE @WORKERID BIGINT
		DECLARE W_CURSOR CURSOR
		FOR SELECT	WorkerID
			FROM	[Worker]
			WHERE	WorkersSalaryID = @workersSalaryID
		OPEN	W_CURSOR
		FETCH	NEXT FROM W_CURSOR INTO @WORKERID
		IF		@@FETCH_STATUS <> 0 PRINT 'table Worker HAS NOT worker'
		WHILE	@@FETCH_STATUS = 0
		BEGIN

			DELETE	DayWorking
			WHERE	WorkerID = @WORKERID
			FETCH	NEXT FROM W_CURSOR INTO @WORKERID
		END
		CLOSE W_CURSOR
		DEALLOCATE W_CURSOR
	DELETE  [Worker]
	WHERE	WorkersSalaryID = @workersSalaryID
	DELETE  [WorkersSalary]
	WHERE	 WorkersSalaryID =@workersSalaryID	
	
END

GO

